<?php
include("./include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  header('location:checkLogin.php');
}

$today = date("d/m/y");
$sellId = $_REQUEST['sellId'];

//Submit Sell Item Detail
if(isset($_REQUEST['submitBtn']))
{
  $amount      = $_REQUEST['amount'];
  $addOnLoanId = $_REQUEST['addOnLoanId'];
  $narration   = $_REQUEST['narration'];
  $date        = $_REQUEST['curDateYear']."-".$_REQUEST['curDateMonth']."-".$_REQUEST['curDateDay'];
  
  //Update Sell Item Detail
  if($addOnLoanId != "")
  {
    $insertSellItem = "UPDATE loan 
                          SET soldAmount    = '".$amount."', 
                              soldDate      = '".$date."', 
                              isSold        = 'Y',
                              soldNarration = '".$narration."'
                        WHERE loanId        = ".$addOnLoanId."
                           OR addOnLoanId   = ".$addOnLoanId ;
  }
  else
  {
    $insertSellItem = "UPDATE loan 
                          SET soldAmount    = '".$amount."', 
                              soldDate      = '".$date."', 
                              isSold        = 'Y',
                              soldNarration = '".$narration."'
                        WHERE loanId        = ".$sellId."
                           OR addOnLoanId   = ".$sellId ;
  }
  $sellItemResult = mysql_query($insertSellItem);
  header("location:soldItem.php");
}
include("./bottom.php");
$smarty->assign("today",$today);
$smarty->display('sellItemDetail.tpl');
?>